package org.pf.base.pfGraphics.staff
{
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.filters.BitmapFilter;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import org.pf.base.pfGraphics.staff.PFImageGeometry;
	import org.pf.base.pfStorages.PFStorageBodySprites;
	import org.pf.constructor.staff.PFBodyGeometry;
	
	/**
	 * ...
	 * @author zeksa'
	 */
	public class DrawBitmap
	{
		
		public static function MakeImageForBody(bodyGeometry:PFBodyGeometry, sprites:PFStorageBodySprites /*, matrix:Matrix = null, ct:ColorTransform = null, qf:BitmapFilter=null*/):Sprite
		{
			var _image:Sprite = new Sprite();
			_image.name = bodyGeometry.bodyName;
			_image.x = bodyGeometry.posX;
			_image.y = bodyGeometry.posY;
			
			var ct:ColorTransform = new ColorTransform();
			var gf:BitmapFilter = new GlowFilter(0x000000, .25, 6, 6, 4, BitmapFilterQuality.MEDIUM, false, false);
			var myFilters:Array = new Array();
			ct.alphaMultiplier = .0;
			
			var _imageTexture:BitmapData = new BitmapData(bodyGeometry.width, bodyGeometry.height, true);
			_imageTexture.colorTransform(new Rectangle(0, 0, bodyGeometry.width, bodyGeometry.height), ct);
			
			var _imageClass:Class;
			_imageClass = sprites.get_image_texture_class(bodyGeometry.textureName);
			
			_imageTexture.draw(new _imageClass());
			var m:Matrix = new Matrix();
			m.tx = -bodyGeometry.width / 2;
			m.ty = -bodyGeometry.height / 2;
			
			_image.graphics.beginBitmapFill(_imageTexture, m, true, true);
			if (bodyGeometry.type != "CIRCLE")
			{
				
				_image.graphics.moveTo(bodyGeometry.vector[0][0], bodyGeometry.vector[0][1]);
				for (var i:int = 1; i < bodyGeometry.vector.length; i++)
				{
					_image.graphics.lineTo(bodyGeometry.vector[i][0], bodyGeometry.vector[i][1]);
				}
				_image.graphics.lineTo(bodyGeometry.vector[0][0], bodyGeometry.vector[0][1]);
			}
			else
			{
				_image.graphics.drawCircle(0, 0, bodyGeometry.width / 2);
			}
			_image.graphics.endFill();
			myFilters.push(gf);
			_image.filters = myFilters;
			return _image as Sprite;
		}
		
		public static function MakeImage(imageGeometry:PFImageGeometry):Sprite
		{
			var img:Sprite = new Sprite();
			img.name = imageGeometry.name;
			img.x = imageGeometry.posX;
			img.y = imageGeometry.posY;
			
			var ct:ColorTransform = new ColorTransform();
			ct.alphaMultiplier = .0;
			
			var _imageTexture:BitmapData = new BitmapData(imageGeometry.width, imageGeometry.height, true);
			_imageTexture.colorTransform(new Rectangle(0, 0, imageGeometry.width, imageGeometry.height), ct);
			
			var _imageClass:Class;
			_imageClass = imageGeometry.i_class;
			
			_imageTexture.draw(new _imageClass());
			var m:Matrix = new Matrix();
			//m.tx = -imageGeometry.width / 2;
			//m.ty = -imageGeometry.height / 2;
			
			img.graphics.beginBitmapFill(_imageTexture, m, true, true);
			//img.graphics.drawRect(-imageGeometry.width/2, -imageGeometry.height/2, imageGeometry.width, imageGeometry.height);
			img.graphics.drawRect(0, 0, imageGeometry.width, imageGeometry.height);
			
			img.graphics.endFill();
			
			return img;
		}
	
	}

}